package cn.wolfcode.web.controller;

import cn.wolfcode.mq.MQConstant;
import cn.wolfcode.mq.OrderMQResult;
import cn.wolfcode.service.ISeckillProductService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消费者监听生成订单出现异常结果消息的处理，同步数据库库存到redis中
 */
@Component
@RocketMQMessageListener(consumerGroup = "orderFailGroup",topic = MQConstant.ORDER_RESULT_TOPIC,selectorExpression = MQConstant.ORDER_RESULT_FAIL_TAG)
public class OrderFailMessageListener implements RocketMQListener<OrderMQResult> {
    @Autowired
    private ISeckillProductService seckillProductService;

    @Override
    public void onMessage(OrderMQResult orderMQResult) {
        // 获取秒杀商品的数据库库存
        // 同步库存到redis中
        seckillProductService.syncStockCount(orderMQResult.getTime(),orderMQResult.getSeckillId());
    }
}
